﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using SurveySystem.Core;

namespace SurveySystem.Web
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");
        }

        protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            MembershipUser user = Membership.GetUser(CreateUserWizard1.UserName);

            TextBox tbPhoneNumber = WebUtils.FindControlRecursive(CreateUserWizard1.CreateUserStep, "tbPhoneNumber") as TextBox;
            TextBox tbFullName = WebUtils.FindControlRecursive(CreateUserWizard1.CreateUserStep, "tbFullName") as TextBox;
            
            CheckBox chkEmailOnNewSurvey = WebUtils.FindControlRecursive(CreateUserWizard1.CreateUserStep, "chkEmailOnNewSurvey") as CheckBox;
            CheckBox chkSmsOnNewSurvey = WebUtils.FindControlRecursive(CreateUserWizard1.CreateUserStep, "chkSmsOnNewSurvey") as CheckBox;
            CheckBox chkEmailOnExpiration = WebUtils.FindControlRecursive(CreateUserWizard1.CreateUserStep, "chkEmailOnExpiration") as CheckBox;
            CheckBox chkSmsOnExpiration = WebUtils.FindControlRecursive(CreateUserWizard1.CreateUserStep, "chkSmsOnExpiration") as CheckBox;


            string mobilePhone = string.IsNullOrEmpty(tbPhoneNumber.Text) ? null : tbPhoneNumber.Text;
            string fullName = string.IsNullOrEmpty(tbFullName.Text) ? null : tbFullName.Text;
            UsersBLL.RegisterUser(user, fullName, mobilePhone, chkEmailOnNewSurvey.Checked, chkSmsOnNewSurvey.Checked, 
                chkEmailOnExpiration.Checked, chkSmsOnExpiration.Checked);
        }

        protected void CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
        {
            
        }

    
    

        
    }
}
